﻿using ModuleCore.Common;
using ModuleCore.Mvvm;

using OpencvsharpModule.Models;
using OpencvsharpModule.Views;

using Prism.Ioc;
using Prism.Modularity;

using System.Linq;
using System.Reflection;

namespace OpencvsharpModule
{
    public class ModuleOpenCVSharp : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {

            var Navigate = containerProvider.Resolve<NavigateModel>();

            var views = from t in Assembly.GetExecutingAssembly().GetTypes()   //
                        where t.GetCustomAttribute<NavigationPageAttribute>() is not null
                        select t;
            foreach (var view in views)
            {
                var page = view.GetCustomAttribute<NavigationPageAttribute>();
                Navigate.NavigateList.Add(new NavigateItem()
                {
                    ViewName = page.ViewName,
                    IconKind = page.IconKind,
                    DisplayName = page.DisplayName,
                    UserLevel = page.UserLevel,
                    Display = page.Display
                });
            }


            Navigate.DefaultView = "CameraView";
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<CalibrateCommon>();
            containerRegistry.RegisterSingleton<CameraModel>();
            containerRegistry.RegisterSingleton<ImagePool>();
            containerRegistry.RegisterSingleton<DataPool>();
            containerRegistry.RegisterSingleton<RoslynEditorModel>();

            containerRegistry.RegisterDialog<CalibrateView, ViewModels.CalibrateViewModel>();


            containerRegistry.RegisterForNavigation<CameraView>();
            containerRegistry.RegisterForNavigation<ThresholdView>();
            containerRegistry.RegisterForNavigation<MorphologyView>();
            containerRegistry.RegisterForNavigation<HoughLinesView>();
            containerRegistry.RegisterForNavigation<RoslynView>();
            containerRegistry.RegisterForNavigation<FeatureMatchingView>();
            containerRegistry.RegisterForNavigation<ConnectedView>();
            containerRegistry.RegisterForNavigation<MaskCopyView>();
            containerRegistry.RegisterForNavigation<CannyView>();
            containerRegistry.RegisterForNavigation<HogSvmView>();
            containerRegistry.RegisterForNavigation<CornersView>();
        }
    }
}